<?php

class Public_Post_EditErrorView extends BlogPublicBaseView
{
	public function executeHtml(AgaviRequestDataHolder $rd)
	{
		$this->setupHtml($rd, 'blog');
		$params = $rd->getParameters();
		$vm = $this->container->getValidationManager();
        /* @var $model Public_PostsModel */
        $model = $this->getContext()->getModel('Posts', 'Public');
		$ro = $this->getContext()->getRouting();
        
		$errors = $vm->getErrors();
        
		if (isset($params['post_id'])) {
            $post = $model->getPost($params['post_id']);
            $route_elements = array('post_id'=>$post->id);
            $action = 'post_by_id';
        } else {
            $date = date_create(sprintf('%s-%s-%s', $params['year'], $params['month'], $params['day']));
            $post = $model->getPost(null, $params['shortcut'], $date);
            $route_elements = array('day' => $params['day'], 'month'=>$params['month'],
            	'year'=>$params['year'], 'shortcut'=>$params['shortcut']);
            $action = 'post';
        }
		
        $this->setAttribute('post_shortcut', $post->shortcut);
        $this->setAttribute('title', 'Edit post');
		$this->setAttribute('errors', $errors);
        $this->setAttribute('submit_route', $ro->gen($action.'.edit', $route_elements));
	}
}

?>
